package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.BookOrder;
import com.xuetang9.t9.hotel.beans.CommodityType;
import com.xuetang9.t9.hotel.beans.EConsumption;
import com.xuetang9.t9.hotel.dto.reqest.ConsumptionDTO;
import com.xuetang9.t9.hotel.mapper.condition.impl.CommodityTypeCondition;
import com.xuetang9.t9.hotel.mapper.condition.impl.EConsumptionCondition;
import com.xuetang9.t9.hotel.services.IEConsumptionService;
import com.xuetang9.t9.hotel.utils.HttpCodeEnum;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName: MyHotelProject
 * @Package: com.xuetang9.t9.hotel.controller
 * @ClassName: EConsumptionController
 * @Author: ChinaHp
 * @Description: 餐饮控制层
 * @Date: 2020/2/24 17:03
 * @Version: 1.0
 */
@Controller
@RequestMapping("ec")
@ResponseBody
public class EConsumptionController {
    @Autowired
    private IEConsumptionService service;

    @PostMapping("addA")
    public boolean addAfterOrder(@RequestBody ConsumptionDTO dto){
        EConsumption eConsumption = new EConsumption(dto.getTablesId(), dto.getStaffId(), dto.getPrice(),dto.getOrderFoods());
        return service.addAfterJoinEat(eConsumption);
    }

    @PostMapping("addF")
    public boolean addFreeOrder(@RequestBody ConsumptionDTO dto){
        EConsumption eConsumption = new EConsumption(dto.getTablesId(), dto.getStaffId(), dto.getPrice(),dto.getOrderFoods());
        return service.addFreeJoinEat(eConsumption);
    }

    @PostMapping("addN")
    public boolean addNowOrder(@RequestBody ConsumptionDTO dto){
        EConsumption eConsumption = new EConsumption(dto.getTablesId(), dto.getStaffId(), dto.getPrice(), dto.getActualPrice(), dto.getOrderFoods());
        return service.addNowJoinEat(eConsumption);
    }

    /**
     * 列表查询
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/show",method = RequestMethod.POST)
    private PageBean show(@RequestBody EConsumptionCondition condition){
        return service.queryByAll(condition);
    }

    private int currPage = 1;
    private Long sumPage ;
    private int size = 5;

    @PostMapping("list")
    public List<EConsumption> queryPageData(){
        sumPage = service.getSumPage(size);
        return service.queryAll();
    }

    @PostMapping("home")
    public void home(){
        currPage = 1;
    }

    @PostMapping("up")
    public void up(){
        if(currPage > 1) {
            currPage--;
        }
    }

    @PostMapping("next")
    public void next(){
        if(currPage < sumPage){
            currPage++;
        }
    }

    @PostMapping("end")
    public void end(){
        currPage = new Long(sumPage).intValue();
    }

    @PostMapping("add")
    public boolean add(){
        return false;
    }

    @PostMapping("update")
    public boolean update(){
        return false;
    }

    @PostMapping("data")
    public Map getData(){
        Map<String, Object> map=new HashMap<String, Object>();
        if(service.getTodayIncome() == null){
            map.put("todayMoney",0);
        }else {
            map.put("todayMoney",service.getTodayIncome());
        }
        map.put("ljMoney",service.getLjMoney());
        map.put("JyMoney",service.getLjMoney());
        return map;
    }

    /**
     * 根据预订订单id查询外带订单
     * @param id
     * @return
     */
    @RequestMapping(value = "/que/{id}")
    private Map show(@PathVariable("id") Integer id){
        Map map  = new HashMap();
        if(id == null ){
            map.put(400,"参数错误");
            return map;
        }
        EConsumption consumption = service.selectByBesides(id);
        if(consumption == null){
            map.put(500,"操作错误");
            return map;
        }
        map.put(200,consumption);
        return map;
    }

    /**
     * 根据预订订单id查询就餐订单
     * @param id
     * @return
     */
    @RequestMapping(value = "/quetable/{id}")
    private Map showId(@PathVariable("id") Integer id){
        Map map  = new HashMap();
        if(id == null ){
            map.put(400,"参数错误");
            return map;
        }
        EConsumption consumption = service.selectByTableId(id);
        if(consumption == null){
            map.put(500,"操作错误");
            return map;
        }
        map.put(200,consumption);
        return map;
    }
}
